package com.fc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fc.dto.TableDTO;
import com.fc.service.CodeGenerateService;
import com.fc.vo.Result;
import com.fc.vo.TableVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequestMapping("/codeGenerate")
public class CodeGenerateController {
    @Autowired
    private CodeGenerateService codeGenerateService;

    @GetMapping("/toIndex" )
    public ModelAndView index(){
        ModelAndView mv=new ModelAndView();
        mv.setViewName("/sysTable/tableList" );
        return mv;
    }

    /**
     * 表列表
     * @param  dto
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/list" )
    @ResponseBody
    public Result<?> list(TableDTO dto,
                          @RequestParam(name = "pageNumber" , defaultValue = "1" ) Integer pageNumber,
                          @RequestParam(name = "pageSize" , defaultValue = "10" ) Integer pageSize){
        Page<TableVO> page=new Page(pageNumber,pageSize);
        page.setRecords(codeGenerateService.getList(page,dto));
        return Result.OK(page);
    }


    /**
     * 代码生成
     * @param  id
     * @return
     */
    @GetMapping("/generate" )
    @ResponseBody
    public Result<?> genererate(String id){
        codeGenerateService.generate(id);
        return Result.OK("已成功生成");
    }



}
